package com.chagee.store.operation.server.controller.pc;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chagee.base.utils.HttpResponse;
import com.chagee.base.utils.HttpResponseUtil;
import com.chagee.base.utils.PaginationData;
import com.chagee.base.utils.PaginationRequest;
import com.chagee.store.operation.api.request.BaseRequest;
import com.chagee.store.operation.server.model.param.ApprovalAppealParam;
import com.chagee.store.operation.server.model.param.TaskExecutionAppealRequest;
import com.chagee.store.operation.api.request.TaskExecutionRequest;
import com.chagee.store.operation.server.model.param.ViewReasonsParam;
import com.chagee.store.operation.server.model.vo.ApprovalAppealReasonResponse;
import com.chagee.store.operation.server.model.vo.mapVO.TaskExecutionMapVo;
import com.chagee.store.operation.api.response.TaskExecutionResponse;
import com.chagee.store.operation.server.service.GenerateWorkOrderAndTaskExecutionTableData;
import com.chagee.store.operation.server.service.TaskExecutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName WorkOrderController  //类名称
 * @Description: //类描述
 * @Author: Jacky-zhan	//作者
 * @CreateDate: 2024/7/2 17:53	//创建时间
 * @UpdateUser: Jacky-zhan  //变更者
 * @UpdateDate: 2024/7/2 17:53	//更新时间
 * @UpdateRemark: //更新的信息
 * @Version: 1.0    //版本号
 */
@Slf4j
@RestController
@RequestMapping("/taskExecution")
@Api("三方打样工单关联任务信息")
public class TaskExecutionController {

	@Resource
	private TaskExecutionService taskExecutionService;

	@Resource
	private GenerateWorkOrderAndTaskExecutionTableData generateWorkOrderAndTaskExecutionTableData;

	@GetMapping("/dict")
	@ApiOperation("数据字典")
	public HttpResponse<TaskExecutionMapVo> dict() {
		return HttpResponseUtil.success(taskExecutionService.dict());
	}

	@PostMapping("/query")
	@ApiOperation("PC端开早打样工单获取工单任务的列表信息")
	public HttpResponse<PaginationData<TaskExecutionResponse>> query(@RequestBody PaginationRequest<TaskExecutionRequest> request) {
		log.info("#TaskExecutionController.query#request{}", request);
		return HttpResponseUtil.success(taskExecutionService.query(request));
	}

	@PostMapping("/queryTaskExecutionList")
	@ApiOperation("PC端开早打样工单获取工单申诉的列表信息")
	public HttpResponse<List<TaskExecutionResponse>> queryTaskExecutionList(@RequestBody @Valid TaskExecutionAppealRequest request) {
		log.info("#TaskExecutionController.queryTaskExecutionList#request{}", request);
		List<TaskExecutionResponse> result = taskExecutionService.queryTaskExecutionList(request);
		return HttpResponseUtil.success(result);
	}

	@PostMapping("/approvalAppeals")
	@ApiOperation("PC端开早打样工单-申诉信息：审批申诉（通过/驳回）")
	public HttpResponse<Boolean> approvalAppeals(@RequestBody @Valid ApprovalAppealParam approvalAppealParam) {
		log.info("#TaskExecutionController.approvalAppeals#request{}, auth:{}", JSONUtil.toJsonStr(approvalAppealParam), JSONUtil.toJsonStr(AuthUtil.getUser()));
		Boolean result = taskExecutionService.approvalAppeals(approvalAppealParam);
		return HttpResponseUtil.success(result);
	}

	@PostMapping("/viewReasons")
	@ApiOperation("PC端开早打样工单-申诉信息：查看驳回的原因/申诉原因")
	public HttpResponse<ApprovalAppealReasonResponse> viewReasons(@RequestBody @Valid ViewReasonsParam viewReasonsParam) {
		log.info("#TaskExecutionController.viewReasons#request{}", viewReasonsParam);
		ApprovalAppealReasonResponse result = taskExecutionService.viewReasons(viewReasonsParam);
		return HttpResponseUtil.success(result);
	}

	@PostMapping("/workOrder/create")
	@ApiOperation("PC端开早打样工单-创建打烊工单")
	public HttpResponse<Boolean> createWorkOrder(@RequestBody @Valid BaseRequest baseRequest) {
		log.info("#TaskExecutionController.createWorkOrder#request{}", JSONObject.toJSONString(baseRequest));
		Boolean result = generateWorkOrderAndTaskExecutionTableData.createWorkOrder(baseRequest.getStoreNo());
		return HttpResponseUtil.success(result);
	}

}
